package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品基本信息
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user)\n" +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addDishInfo(Dish dish);



    /**
     * 菜品分页查询
     * @param queryDTO
     * @return
     */
    Page<DishVO> getDishPage(DishPageQueryDTO queryDTO);

    /**
     * 根据菜品id查询起售状态的数量
     * @param ids
     * @return
     */
    Integer getCountStatus(List<Long> ids);

    /**
     * 根据ID删除菜品
     * @param ids
     */
    void deleteDishById(List<Long> ids);

    /**
     * 根据ID查询菜品基本信息
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    DishVO queryDishInfoById(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDishInfo(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select  * from dish where status = 1 and category_id = #{categoryId}")
    List<Dish> queryAllDishByCategoryId(Long categoryId);
}
